package com.lagou.dao;

import com.lagou.domain.Student;
import com.lagou.utils.DruidUtils;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class StudentDao {
    public static int addStudent(Student student) {
        int res = 0;

        Connection con = null;
        PreparedStatement ps = null;

        try {
            con = DruidUtils.getConnection();

            String sql = "insert into student (number,name,sex,birthday) values (?,?,?,?)";
            ps = con.prepareStatement(sql);

            ps.setInt(1,student.getNumber());
            ps.setString(2, student.getName());
            ps.setString(3, student.getSex());
            ps.setDate(4, new Date(student.getBirthday().getTime()));

            res = ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DruidUtils.close(con, ps);
        }

        return res;
    }
}
